/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package arrayManipulation;

/**
 *
 * @author cooler
 */
import java.nio.*;  //Byte Int conversion classes


public class Conversion {
    public Conversion() {
    
    }
    
    //http://stackoverflow.com/questions/12320000/efficiently-send-large-int-over-sockets-in-java
    public static byte[] intToByte(int[] input) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(input.length * 4);
        IntBuffer intBuffer = byteBuffer.asIntBuffer();
        intBuffer.put(input);

        byte[] array = byteBuffer.array();

        return array;
    }

    public static int[] byteToInt(byte[] input) {

        int[] array = new int[input.length / 4];

        for (int i = 0; i < input.length / 4; i++) {
            array[i] = input[i * 4 + 3];
        }

        return array;
    }
    
}

